package client;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.Serializable;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Inizia extends JFrame implements ActionListener,Serializable{
		
		public JButton nuovo;
		public JButton login;
		public JButton esci;
		
		private int risp ;
		
		public Inizia(){
			super("Schermata iniziale");
			setExtendedState(MAXIMIZED_BOTH);
			setDefaultCloseOperation(EXIT_ON_CLOSE);
			setLayout(new BorderLayout());
			GridBagConstraints c = new GridBagConstraints();
			c.fill = GridBagConstraints.CENTER;
			nuovo = new JButton("Crea nuovo utente");
			login = new JButton("Login");
			esci = new JButton("Esci");
			
			nuovo.addActionListener(this);
			login.addActionListener(this);
			esci.addActionListener(this);
			
			JPanel pannello1 = new JPanel();
			pannello1.setLayout(new FlowLayout());
			
			pannello1.add(nuovo);
			pannello1.add(login);
			pannello1.add(esci);
			
			pannello1.setOpaque(false);	
			
			PannelloSfondo pannello = new PannelloSfondo(new File("sfondo2.jpg"));
			pannello.setLayout(new GridBagLayout());
			
			pannello.setPreferredSize(new Dimension(1500,600));
			
			pannello1.setOpaque(false);		
			pannello.add(pannello1, c);
			
			
			add(pannello, BorderLayout.CENTER);
			setVisible(true);
			
			synchronized(this){
				try {
					wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			synchronized(this){
				if(e.getSource().equals(nuovo)){
					risp=2;
					notifyAll();
					dispose();
				}
			}
			synchronized(this){
				if(e.getSource().equals(login)){
					risp=1;
					notifyAll();
					dispose();
				}
			}
			synchronized(this){
				if(e.getSource().equals(esci)){
					risp=3;
					notifyAll();
					dispose();
				}
			}
		}
		
		public int getRisp(){
			return risp;
		}
		
}


